package com.kevin.mybatis.service.impl;

import com.kevin.mybatis.model.DataScope;
import com.kevin.mybatis.model.LoginUser;
import com.kevin.mybatis.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    private static DataScope DATA_SCOPE = DataScope.ALL;

    @Override
    public DataScope datascope(DataScope dataScope) {
        DATA_SCOPE = dataScope;
        return DATA_SCOPE;
    }

    @Override
    public LoginUser getLoginUser() {
        LoginUser user = new LoginUser();
        switch (DATA_SCOPE) {
            case ALL:
                // 全部
                user.setUserId(1L);
                user.setOrgId(1L);
                user.setDatascope(1);
                break;
            case CUS:
                // 自定义
                user.setUserId(1L);
                user.setOrgId(1L);
                user.setDatascope(2);
                user.setRangeList(new Long[]{2L, 3L, 4L}); // 组织ID集合
                break;
            case CURRENT_SUB:
                // 组织层级关系
                user.setUserId(1L);
                user.setOrgId(1L);
                user.setDatascope(3);
                user.setRangeList(new Long[]{1L, 2L, 3L, 4L}); // 组织ID集合
                break;
            case CURRENT:
                // 当前组织
                user.setUserId(1L);
                user.setOrgId(1L);
                user.setDatascope(4);
                user.setRangeList(new Long[]{1L}); // 组织ID
                break;
            case MYSELF:
                // 自己操作的数据
                user.setUserId(1L);
                user.setOrgId(1L);
                user.setDatascope(5);
                user.setRangeList(new Long[]{1L}); // 用户ID
                break;
        }
        return user;
    }

}
